{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

<div class="boxed-section">
    <div class="boxed-section-head">Job Plan</div>
    <div class="boxed-section-body is-dark">
    <JobDiff
        data-test-plan-output
        @diff={{@data.planOutput.diff}}
        @verbose={{false}}
    />
    </div>
</div>

<Hds::Alert @type="inline" @color={{if @data.planOutput.failedTGAllocs "critical" "success"}} data-test-dry-run-message as |A|>
  <A.Title data-test-dry-run-title>Scheduler dry-run</A.Title>
  <A.Description data-test-dry-run-body>
    {{#if @data.planOutput.failedTGAllocs}}
      {{#each @data.planOutput.failedTGAllocs as |placementFailure|}}
        <PlacementFailure @failedTGAlloc={{placementFailure}} />
      {{/each}}
    {{else}}
      All tasks successfully allocated.
    {{/if}}
  </A.Description>
</Hds::Alert>
<br>

{{#if this.warnings}}
  <Hds::Alert @type="inline" @color="warning" data-test-dry-run-warnings as |A|>
    <A.Description data-test-dry-run-warning-body>
      <p>
        {{this.warnings}}
      </p>
    </A.Description>
  </Hds::Alert>
  <br>
{{/if}}

{{#if
    (and
    @data.planOutput.preemptions.isFulfilled @data.planOutput.preemptions.length
    )
}}
    <div class="boxed-section is-warning" data-test-preemptions>
    <div class="boxed-section-head" data-test-preemptions-title>
        Preemptions (if you choose to run this job, these allocations will be
        stopped)
    </div>
    <div class="boxed-section-body" data-test-preemptions-body>
        <ListTable
        @source={{@data.planOutput.preemptions}}
        @class="allocations is-isolated"
        as |t|
        >
        <t.head>
            <th class="is-narrow"><span class="visually-hidden">Driver Health, Scheduling, and Preemption</span></th>
            <th>ID</th>
            <th>Task Group</th>
            <th>Created</th>
            <th>Modified</th>
            <th>Status</th>
            <th>Version</th>
            <th>Node</th>
            <th>Volume</th>
            <th>CPU</th>
            <th>Memory</th>
        </t.head>
        <t.body as |row|>
            <AllocationRow @allocation={{row.model}} @context="job" />
        </t.body>
        </ListTable>
    </div>
    </div>
{{/if}}
<Hds::ButtonSet class="is-associative">
    <Hds::Button @text="Run" {{on "click" (perform @fns.onSubmit)}} disabled={{@fns.onSubmit.isRunning}} data-test-run />
    <Hds::Button @color="secondary" @text="Cancel" {{on "click" @fns.onReset}} disabled={{@fns.onSubmit.isRunning}} data-test-cancel />
</Hds::ButtonSet>
